<?php
    
    include_once '../../controlador/php/conexion/Conexion10.php';
    $con = new Conexion10();
    
    $pac = $_REQUEST['pac'];
    
    $deteccion = "SELECT TOP 1 HCFECFOL, AINCONSEC, PACNUMDOC, PACPRINOM+' '+PACSEGNOM+' '+PACPRIAPE+' '+PACSEGAPE AS NOMBRES,
                  CONVERT(NVARCHAR(5),HCCM09N02) AS '_3',
                  CONVERT(NVARCHAR(5),HCCM09N05) AS '_4',
                  CONVERT(NVARCHAR(100),HCCM04N19) AS '_4cual', 
                  CONVERT(NVARCHAR(5),HCCM09N04) AS '_5', 
                  CONVERT(NVARCHAR(100),HCCM04N57) AS '_5cual', 
                  CONVERT(NVARCHAR(5),HCCM09N10) AS '_6', 
                  CONVERT(NVARCHAR(5),HCCM09N14) AS '_9', 
                  CONVERT(NVARCHAR(5),HCCM09N13) AS '_10', 
                  CONVERT(NVARCHAR(100),HCCM04N08) AS '_10cual', 
                  CONVERT(NVARCHAR(5),HCCM09N17) AS '_11', 
                  CONVERT(NVARCHAR(5),HCCM09N21) AS '_16', 
                  CONVERT(NVARCHAR(5),HCCM09N24) AS '_18', 
                  CONVERT(NVARCHAR(5),HCCM09N26) AS '_19', 
                  CONVERT(NVARCHAR(5),HCCM09N41) AS '_33', 
                  CONVERT(NVARCHAR(100),HCCM03N43) AS '_33cual' 
                  FROM HCMHODETE 
                  INNER JOIN HCNFOLIO ON HCMHODETE.HCNFOLIO = HCNFOLIO.OID 
                  INNER JOIN HCNTIPHIS ON HCNFOLIO.HCNTIPHIS = HCNTIPHIS.OID 
                  INNER JOIN ADNINGRESO ON HCNFOLIO.ADNINGRESO = ADNINGRESO.OID 
                  INNER JOIN GENPACIEN ON ADNINGRESO.GENPACIEN = GENPACIEN.OID 
                  WHERE HCCODIGO='HODETE' AND AINESTADO='0' AND PACNUMDOC = '".$pac."'
                  ORDER BY PACNUMDOC, HCFECFOL DESC";
    $res = $con->query($deteccion);
    
    while ($res2 = mssql_fetch_array($res)){
        
        $lista[] = array_map(utf8_encode,$res2);
    }
    
     print_r(json_encode($lista));
    
    $con->cerrarConexion();
    
?>